package swa.telco.impl;

import java.util.Collection;
import java.util.Hashtable;
import java.util.Vector;

import swa2012.telco.broker.beans.Message;

public class MessageContainer {

	private Hashtable<String, Vector<Message>> container;
	
	public MessageContainer(){
		container = new Hashtable<String, Vector<Message>>();
	}
	
	public void add(Message msg){
		String receiverID = msg.getReceiver().getID();
		if(receiverID!=null && !receiverID.isEmpty()){
			if(!container.containsKey(receiverID)){
				container.put(receiverID, new Vector<Message>());
			}
			container.get(receiverID).add(msg);
		}
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Collection<Message> getMessages(String clientID){
		Collection tmpCollMsgs = (Collection)container.get(clientID);
		container.remove(clientID);
		return tmpCollMsgs;
	}
	
}
